package com.example.demo31;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.charset.StandardCharsets;

public class MainActivity extends AppCompatActivity  {

    //声明控件
    private Button mbtnlogin;
    private EditText Ediusername;
    private EditText Edipassword;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_main);
        //找到控件
        mbtnlogin = findViewById(R.id.btn_1);
        Ediusername = findViewById(R.id.ed_1);
        Ediusername = findViewById(R.id.ed_2);


        //实现跳转 --方法一
         mbtnlogin.setOnClickListener(new View.OnClickListener() {
            @Override
                public void onClick(View v) {
                Intent intent = null;
                intent = new Intent(MainActivity.this,FunctionActivity.class);
               startActivity(intent);

            }
        });

   //     mbtnlogin.setOnClickListener(this::Onclick);

        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });
    }



  //  public void Onclick(View view)
  //  {
  //     String username = Ediusername.getText().toString();
  //     String password = Edipassword.getText().toString();
  //     Intent intent = null;

 //      if(username.equals("xhx")&&password.equals("123456"))
 //      {
//           intent = new Intent(this, FunctionActivity.class);
//           startActivity(intent);
 //      }
 //      else {
//
 //      }
//    }


    public void todetail(View view) {
        Intent intent = new Intent(this, RegisterActivity.class);
        startActivity(intent);
    }
    public void tomytest(View view) {
        Intent intent = new Intent(this,DialogActivity2.class);
        startActivity(intent);
    }
    public void totestAC(View view) {
        //方法一：用putExtra跟getExtra来进行跳转页面的数据传参
        Intent intent = new Intent(this,testActivity.class);
        Bundle bundle  = new Bundle();
        bundle.putString("name","xhx");
        bundle.putInt("age",18);
        intent.putExtras(bundle);
        //intent.putExtra("name","xhx");
        //intent.putExtra("age" ,18);
        //startActivity(intent);
        startActivityForResult(intent,100);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(requestCode==RESULT_OK&&requestCode==100)
        {
            String res = data.getStringExtra("result");
            Toast.makeText(this,res,Toast.LENGTH_SHORT).show();
        }
    }
    public void totestdl(View view) {
        Intent intent = new Intent(this, WechatActivity.class);
        startActivity(intent);
    }


}